package org.binglan.youziyuepai.mapper;

import org.apache.ibatis.annotations.Select;
import org.binglan.youziyuepai.entity.Image;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * <p>
 * 图片表 Mapper 接口
 * </p>
 *
 * @author sanjin
 * @since 2019-04-09
 */
public interface ImageMapper extends BaseMapper<Image> {

    /**
     * 通过活动id查询活动场地图片
     * @param activityId
     * @return
     */
    @Select("SELECT i.id,i.url FROM image i, activity_to_image ai WHERE i.id = ai.image_id AND ai.activity_id =#{activityId}")
    List<Image> queryImageByActivityId(Integer activityId);

    /**
     * 通过动态id查询用户发表图片
     * @param personalDynamicId
     * @return
     */
    @Select("SELECT\n" +
            "\ti.*\n" +
            "FROM\n" +
            "\timage i,\n" +
            "\tpersonal_dynamic_to_image pi\n" +
            "WHERE\n" +
            "\ti.id = pi.image_id \n" +
            "\tAND pi.personal_dynamic_id = #{personalDynamicId}")
    List<Image> queryImageByPersonalDynamicId(String personalDynamicId);
}
